package liurong.driver.time;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import org.junit.Test;

public class CalendarTest {
	@Test
	public void fun1() {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(new Date());
		calendar.set(Calendar.DATE, 1);
		System.out.println("本月第一天------------------" + simpleDateFormat.format(calendar.getTime()));
		// 下一月的今天
		calendar.setTime(new Date());
		calendar.add(Calendar.MONTH, 1);
		System.out.println("下一月的今天-----------------" + simpleDateFormat.format(calendar.getTime()));
		// 下月第一天
		calendar.set(Calendar.DATE, 1);
		System.out.println("下月第一天------------------" + simpleDateFormat.format(calendar.getTime()));
		// 下月第一天减一天（及是本月第一天）
		calendar.add(Calendar.DATE, -1);
		System.out.println("下月第一天减一天（即是本月第一天）--" + simpleDateFormat.format(calendar.getTime()));

	}

	@Test
	public void fun2() throws ParseException {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Date date1 = simpleDateFormat.parse("2019-04-24");
		Date date2 = simpleDateFormat.parse("2020-01-01");
		System.out.println((date2.getTime() - date1.getTime()) / 1000 / 60 / 60 / 24.0);

		System.out.println((252 - 15) / 365.0 * 18 * 2);
		System.out.println((252) / 365.0 * 18 * 2);
	}

	@Test
	public void date() throws Exception {
		SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		calendar.setTime(simpleDateFormat.parse("2019-04-24"));
		calendar.add(Calendar.DATE, 160);
		System.out.println("上班时间------------------" + simpleDateFormat.format(calendar.getTime()));
	}
}
